import pytest
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from time import sleep
from faker import Faker
faker = Faker(locale='zh_cn')
name = faker.name()
import pytest
import allure

base_url = "http://121.43.29.41:8899/admin/login"
@allure.feature("登录")
class TestDemo4:
    @allure.story('最大化')
    def setup_method(self):
        self.driver = webdriver.Chrome()
        self.driver.maximize_window()
    @allure.story('退出浏览器')
    def teardown_method(self):
        sleep(10)
        self.driver.quit()  # 退出浏览器

    @allure.story('登录成功')
    def test_crmeb(self):
        self.driver.get(base_url)
        with allure.step("账号"):
            print("账号")
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, 'el-input__inner')))[0].send_keys("admin")
        sleep(2)
        #输入密码
        with allure.step("密码"):
            print("密码")
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,'el-input__inner')))[1].send_keys("admin123.")

        #点击登录按钮
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.CLASS_NAME,'el-button'))).click()
        #等待页面主页加载
        sleep(5)


        #点击用户tap
        WebDriverWait(self.driver,10,0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,'font12')))[1].click()
        # 点击用户标签
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located(
            (By.XPATH, '//*[@id="app"]/section/div[2]/aside/div[2]/div[1]/div/div/ul/li[3]/span'))).click()
        sleep(3)
        # 添加标签
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located((By.XPATH,'//*[@id="app"]/section/div[2]/section/div/div[1]/div/main/div/div[1]/div/div[1]/div/div/div[2]/div/div/div[1]/div/button/span'))).click()
        sleep(3)
        # 全部
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, 'el-input__inner')))[2].click()
        sleep(3)
        #客户来源
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, 'el-select-dropdown__item')))[5].click()
        sleep(3)

        # 添加标签
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, 'el-input__inner')))[3].send_keys(str(name))
        sleep(3)
        # 点确定
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, 'el-button ')))[2].click()
        sleep(3)

        #删除
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.XPATH, '//*[text()="删除"]')))[-1].click()
        WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, 'el-button')))[-1].click()



        # #点击用户分组
        # WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[text()="用户分组"]'))).click()
        # sleep(2)
        #
        # #点击添加分组
        # WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,'//*[text()="添加分组"]'))).click()
        # sleep(1)
        #
        # #输入分组名称
        # WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, 'el-input__inner')))[
        #     2].send_keys(str(name))
        #
        # #点击确定按钮
        # WebDriverWait(self.driver,10,0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,'el-button')))[-1].click()
        # sleep(3)
        #
        # #断言
        # text = WebDriverWait(self.driver,10,0.5).until(EC.presence_of_element_located((By.XPATH,f'//*[text()="{name}"]'))).text
        # assert text == name
        #
        # #修改刚新增的分组
        # WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.XPATH, '//*[text()="修改"]')))[-1].click()
        # sleep(2)
        #
        # #输入修改分组名称
        # group_name =WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME, 'el-input__inner')))[2]
        # group_name.clear()
        # group_name.send_keys('11')
        #
        # #点击确定按钮
        # WebDriverWait(self.driver,10,0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,'el-button')))[-1].click()
        # sleep(3)        # 等待刚新增的分组加上去了
        #
        # #删除刚才修改的分组
        # WebDriverWait(self.driver,10,0.5).until(EC.presence_of_all_elements_located((By.XPATH,'//*[text()="删除"]')))[-1].click()
        # sleep(2)
        #
        # #点击确认删除按钮
        # WebDriverWait(self.driver,10,0.5).until(EC.presence_of_all_elements_located((By.CLASS_NAME,'el-button')))[-1].click()

        #等待页面
        # sleep(10)
